package com.zzz.web.daoimpl;

import com.zzz.web.Data.NewRssi;
import com.zzz.web.dao.NewRssiDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class NewRssiDaoImpl implements NewRssiDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void add(NewRssi newRssi) {
        String sql = "REPLACE INTO newrssi VALUES (?,?,?,?,?,?,?,?,?) ";
        Object[] args={
                newRssi.getX(),
                newRssi.getY(),
                newRssi.getFrequency(),
                newRssi.getAp1Mac(),
                newRssi.getAp1Rssi(),
                newRssi.getAp2Mac(),
                newRssi.getAp2Rssi(),
                newRssi.getAp3Mac(),
                newRssi.getAp3Rssi(),
        };
        jdbcTemplate.update(sql,args);
    }

    @Override
    public List<NewRssi> selectAll() {
        String sql = "select * from newrssi";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<NewRssi>(NewRssi.class));
    }
}
